package com.gwcloud.leetcode.hot100;

import com.gwcloud.leetcode.common.datastructure.ListNode;

/**
 *
 * @copyright ganwei
 * @project coffeejava
 * @date 2020年4月29日
 * @author ganwei
 * 
 * @desc leetcode 141. 环形链表
 * @tag 链表、双指针
 */
public class Leetcode0141 {

	/**
	 * 解题思路-快慢指针 快指针走两步 慢指针走一步
	 */
	public static boolean hasCycle(ListNode head) {
		if (head == null) {
			return false;
		}
		
		ListNode slow = head;
		ListNode fast = head.next;
		
		while(fast != null && fast.next != null){
			if(fast == slow){
				return true;
			}
			slow = slow.next;
			fast = fast.next.next;
		}
		
		return false;
	}

	public static void main(String args[]) {

	}
}
